import { createRouter, createWebHistory } from "vue-router"

const routes = [
  {
    path: '/redirect',
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('../views/redirect.vue')
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/loginRegister/login.vue'),
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('../views/loginRegister/register.vue'),
  },
  {
    path: '',
    redirect: '/login'
  },
  {
    path: '/admin',
    component: () => import('../views/layout.vue'),
    redirect: '/admin/index',
    children: [
      {
        path: '/admin/index',
        name: 'index',
        meta: {
          title: '房圈动态'
        },
        component: () => import('../views/dynamics/index.vue')
      },
      {
        path: '/admin/roomManage',
        name: 'roomManage',
        redirect: '/admin/roomManage/list',
        component: () => import('../views/roomManage/layout.vue'),
        children: [
          {
            path: '/admin/roomManage/list',
            name: 'roomManageList',
            meta: {
              title: '房源管理'
            },
            component: () => import('../views/roomManage/list.vue')
          },
          {
            path: '/admin/roomManage/addEdit',
            name: 'addEditRoom',
            component: () => import('../views/roomManage/addEditRoom.vue')
          },
          {
            path: '/admin/roomManage/detail',
            meta: {
              title: '房源详情'
            },
            component: () => import('../views/roomManage/detail.vue')
          }
        ]
      },
      {
        path: '/admin/ownerManage',
        name: 'ownerManage',
        redirect: '/admin/ownerManage/list',
        component: () => import('../views/ownerManage/layout.vue'),
        children: [
          {
            path: '/admin/ownerManage/list',
            meta: {
              title: '房东管理'
            },
            component: () => import('../views/ownerManage/list.vue')
          },
          {
            path: '/admin/ownerManage/detail',
            meta: {
              title: '房东信息'
            },
            component: () => import('../views/ownerManage/detail.vue')
          }
        ]
      },
      {
        path: '/admin/userManage',
        name: 'userManage',
        redirect: '/admin/userManage/list',
        component: () => import('../views/userManage/layout.vue'),
        children: [
          {
            path: '/admin/userManage/list',
            meta: {
              title: '用户管理'
            },
            component: () => import('../views/userManage/list.vue')
          },
          {
            path: '/admin/userManage/detail',
            meta: {
              title: '用户详情'
            },
            component: () => import('../views/userManage/detail.vue')
          }
        ]
      },
      {
        path: '/unauthorize',
        name: 'unauthorize',
        component: () => import('../views/unauthorize.vue')
      }
    ]
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router